package com.onekbase.demo.thead;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo1 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1);

        for (int num = 0; num < 3; num++){
            new Thread(() ->{
                try {
                    //准备完毕,运动员都阻塞在这里,等待号令
                    countDownLatch.await();
                    System.out.println(Thread.currentThread().getName()+"开始跑……");
                } catch (InterruptedException e) {
                   e.printStackTrace();
                }
            }).start();
        }
        // 发号员准备发令
        Thread.sleep(2000);
        // 发令枪：发令
        countDownLatch.countDown();
    }
}
